<?php
class Permiso extends CI_Controller {
		
		function Permiso () {
			parent::__construct();
			
			$this->load->helper('url');
			$this->load->helper('form');
			

		}
		
		function index () {
			$data['title']='Permiso';
			$data['heading']='Agregar Permiso';
			
			$data['result']= $this->getAllOrderBy('permiso');
			$permiso = new Entities\Permiso;
			$data['registro']=$permiso;
			$data['action']='agregar';
			$data['submit']='Agregar';
			$this -> load -> view('permiso_view',$data);
		}
		
		public function getAll()
		{
		    $permisos = $this->doctrine->em->getRepository('Entities\Permiso')->findAll();
			return $permisos;
		}
		
		public function getAllOrderBy($orden)
		{
		    //
		    $permisos = $this->doctrine->em->createQuery('SELECT p FROM Entities\Permiso p ORDER BY p.'. $orden .' ASC')->getResult(); 
			return $permisos;
		}
		
		public function remove ($id)
		{
			$permiso = $this->doctrine->em->find('Entities\Permiso',$id);
			$this->doctrine->em->remove($permiso);
			$this->doctrine->em->flush();
			redirect('permiso');
		}
		
		public function agregar()
		{
			$permiso = new Entities\Permiso;
    		$permiso->setPermiso($_POST["tx_permiso"]);
		
    		$this->doctrine->em->persist($permiso);
    		$this->doctrine->em->flush();
    		redirect('permiso');
 
		}
		
		public function editar ($id)
		{
			$permiso = $this->doctrine->em->find('Entities\Permiso',$id);
			$data['title']='Permiso';
			$data['heading']='Actualizar Permiso';
			
			$data['result']= $this->getAllOrderBy('permiso');
			$data['registro']=$permiso;
			$data['action']='actualizar';
			$data['submit']='Actualizar';
			$this -> load -> view('permiso_view',$data);
		}
		
		public function actualizar($id)
		{
			$permiso = $this->doctrine->em->find('Entities\Permiso',$id);
    		$permiso->setPermiso($_POST["tx_permiso"]);
    		$this->doctrine->em->persist($permiso);
    		$this->doctrine->em->flush();
    		redirect('permiso');
		}
}
?>